package com.gxa.learning.portal.config;

import com.gxa.learning.portal.interceptor.AuthInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器的注册器设定拦截哪些方法
 *
 * @author YXQ
 * @date 2021/12/14 21:12
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加注册器,设置哪些路径会被拦截
        // 这样设置了只拦截哪些内容，缩小了拦截范围，一些不需要拦截的资源就不会被拦截
        registry.addInterceptor(getAuthInterceptor())
                .addPathPatterns("/main/**")
                .addPathPatterns("/myPage/**")
                .addPathPatterns("/Question/**")
                .addPathPatterns("/msg/**")
                .addPathPatterns("/studyPlan/**")
        ;
    }

    @Bean
    public AuthInterceptor getAuthInterceptor() {
        return new AuthInterceptor();
    }
}
